@Echo off

REM %1 - name of wsp file 
REM %2 - Url - optional

IF X%1==X (
	REM Check for Empty string for path to wsp
	Echo Solution name cannot be empty
	Exit /b -1	
)

REM Change this path if it is differnet in your environment
@SET STSADM="%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"

REM Check for path exists for stsadm command
IF NOT EXIST %STSADM%  (
	Echo Stsadm path %STSADM% does not exists
	Exit /b -1	
)

Echo Retracting Solution %1 from farm
IF X%2==X (
	REM For Uninstall if %2 is empty then Url is not available for retracting
	Echo Retracting No url
	%STSADM% -o retractsolution -name %1 -immediate
	) ELSE (
	Echo Retracting With url %2	
	%STSADM% -o retractsolution -name %1 -immediate -url %2
	) 

Echo calling execadmsvc to start the timerjob to retract the solution
%STSADM% -o execadmsvcjobs


Echo Deleting the solution %1 from farm
%STSADM% -o deletesolution -name %1 -override

Echo calling execadmsvc to start the timerjob to delete the solution
%STSADM% -o execadmsvcjobs

%STSADM% -o copyappbincontent